//
//  FRMacros.h
//  Health
//
//  Created by mykoma on 14-9-7.
//  Copyright (c) 2014年 scu.edu. All rights reserved.
//

#ifndef __HEALTH_MACROS_H__
#define __HEALTH_MACROS_H__

/***************单例模式宏**************/

#define MACRO_SHARED_INSTANCE_INTERFACE +(instancetype)sharedInstance;

#define MACRO_SHARED_INSTANCE_IMPLEMENTATION(CLASS) \
+(instancetype)sharedInstance \
{ \
    static CLASS * sharedInstance = nil; \
    static dispatch_once_t onceToken; \
    dispatch_once(&onceToken, ^{ \
        sharedInstance = [[CLASS alloc] init]; \
    }); \
    return sharedInstance; \
}

/***************字典设置宏**************/

#define DICT_SET_STRING(STRING_VALUE, KEY, DICT) \
{ STRING_VALUE.length > 0 ? DICT[KEY] = STRING_VALUE : nil ; }

#define DICT_SET_INT(INT_VALUE, KEY, DICT) \
{ DICT[KEY] = [@(INT_VALUE) stringValue] ; }

#define DICT_SET_OBJECT(OBJECT_VALUE, KEY, DICT) \
{ OBJECT_VALUE != nil ? DICT[KEY] = OBJECT_VALUE : nil ; }

/***************UIView调试宏**************/

#define UI_DEBUG_SHOW_BORDER(view) \
{ \
view.layer.borderWidth = 0.5f; \
view.layer.borderColor = [UIColor redColor].CGColor; \
} \

#define LOG_DEBUG_RECT(rect) \
NSLog(@"===  %lf  %lf  %lf  %lf", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);


/***************RAC错误处理宏**************/
#define RAC_ERROR_HANDLER \
NSString * tips = error.localizedDescription; \
if ([error.domain isEqualToString:FR_ERROR_BUSNIESS_DOMAIN]) \
{ \
    tips = error.userInfo[FR_TAGS_ERROR][FR_TAGS_TIP]; \
} \
[SVProgressHUD showErrorWithStatus:tips];

#define DICT_VALUE(dict, key) \
[dict[key] isKindOfClass:[NSNull class]] || dict[key] == nil ? @"" : dict[key];

#endif
